package edu.hnnu.sport_event.controller;

import edu.hnnu.sport_event.service.AdminServiceImp;
import edu.hnnu.sport_event.service.EventService;
import edu.hnnu.sport_event.service.StudentServiceImp;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
public class HelloController {

    @Value("${Administrative.email}")
    private String email;
    @Value("${Administrative.message}")
    private String message;

    @Resource
    EventService eventService;
    @Resource
    StudentServiceImp studentService;
    @Resource
    AdminServiceImp  adminServiceImp;

    @RequestMapping("/")
    public String index(HttpServletResponse response) {
        String localDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).toString();

        Cookie dateCookie = new Cookie("time", localDate.toString());
        Cookie emailCookie = new Cookie("email", email);
        Cookie messageCookie = new Cookie("message", message);

        response.addCookie(dateCookie);
        response.addCookie(emailCookie);
        response.addCookie(messageCookie);
        return "login.html";
    }

    @RequestMapping("admin")
    public String sendToAdminPage() {
        return "admin/adhomepage.html";
    }

    @RequestMapping("student")
    public String sendToStudentPage(HttpServletResponse response) {
//        Cookie status = new Cookie("event", eventService.signUpEvents(studentId).toString());
//        response.addCookie(status);
        return "player/pyhomepage.html";
    }

    @RequestMapping("name")
    @ResponseBody
    public String getName(Integer studentId) {
        return studentService.getStudentName(studentId);
    }

    @RequestMapping("aname")
    @ResponseBody
    public String getAdminName(Integer adminId) {
        return adminServiceImp.getName(adminId);
    }

}
